1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import java.util.Locale;
29 import java.util.ResourceBundle;
30 import java.util.Enumeration;
31 import java.io.PrintStream;
32
33 public class GenerateKeyList {
34 public static void main(String[] args) throws Exception {
35 doOutputFor("sun.util.resources", "CalendarData", System.out);
36 doOutputFor("sun.util.resources", "CurrencyNames", System.out);
37 doOutputFor("sun.util.resources", "LocaleNames", System.out);
38 doOutputFor("sun.util.resources", "TimeZoneNames", System.out);
39 doOutputFor("sun.text.resources", "CollationData", System.out);
40 doOutputFor("sun.text.resources", "FormatData", System.out);
41 };
42
43 public static void doOutputFor(String packageName,
44 String resourceBundleName, PrintStream out)
45 throws Exception {
46 Locale[] availableLocales = Locale.getAvailableLocales();
47
48 ResourceBundle bundle = ResourceBundle.getBundle(packageName +
49 resourceBundleName, new Locale("", "", ""));
50 dumpResourceBundle(resourceBundleName + "/", bundle, out);
51 for (int i = 0; i < availableLocales.length; i++) {
52 bundle = ResourceBundle.getBundle(packageName + resourceBundleName,
53 availableLocales[i]);
54 dumpResourceBundle(resourceBundleName + "/" + availableLocales[i].toString(),
55 bundle, out);
56 }
57 }
58
59 public static void dumpResourceBundle(String pathName, ResourceBundle bundle,
60 PrintStream out) throws Exception {
61 Enumeration keys = bundle.getKeys();
62 while(keys.hasMoreElements()) {
63 String key = (String)(keys.nextElement());
64 dumpResource(pathName + "/" + key, bundle.getObject(key), out);
65 }
66 }
67
68 public static void dumpResource(String pathName, Object resource, PrintStream out)
69 throws Exception {
70 if (resource instanceof String[]) {
71 String[] stringList = (String[])resource;
72 for (int i = 0; i < stringList.length; i++)
73 out.println(pathName + "/" + i);
74 }
75 else if (resource instanceof String[][]) {
76 String[][] stringArray = (String[][])resource;
77 if (pathName.startsWith("TimeZoneNames")) {
78 for (int i = 0; i < stringArray.length; i++)
79 for (int j = 0; j < stringArray[i].length; j++)
80 out.println(pathName + "/" + i + "/" + j);
81 }
82 else {
83 for (int i = 0; i < stringArray.length; i++)
84 out.println(pathName + "/" + stringArray[i][0]);
85 }
86 }
87 else
88 out.println(pathName);
89 }
90 }